package liumengbaio.lolzhangyoubao.Activity.Fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;

import java.util.ArrayList;
import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.Activity.MoreEquipDetailsActivity;
import liumengbaio.lolzhangyoubao.Activity.Adapter.MoreEquipSecondAdapter;
import liumengbaio.lolzhangyoubao.Activity.InFo.EquipInfo;
import liumengbaio.lolzhangyoubao.Activity.utils.EquipUtils;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/9/19.
 */
public class FragmentEqipRemove extends Fragment {

    private GridView mGridView;
    private List<EquipInfo> lists;
    private MoreEquipSecondAdapter adapter;
    private List<EquipInfo> removeLists;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.more_equip_grid, null);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView(getView());
        initData();
        initEvent();
    }

    private void initView(View view) {
        mGridView = (GridView) view.findViewById(R.id.more_gridView);
        removeLists = new ArrayList<>();
    }

    private void initData() {
        lists = EquipUtils.getEquipInfo(getActivity());
/**
 * 给物品进行分类
 */
        for (int i = 0; i < lists.size(); i++) {
            String filter = lists.get(i).getFilter();
            if (filter.contains("已移除")) {
                removeLists.add(lists.get(i));
            }
        }
        adapter = new MoreEquipSecondAdapter(getActivity(), removeLists);
        mGridView.setAdapter(adapter);
    }

    private void initEvent() {
        mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(getActivity(), MoreEquipDetailsActivity.class);
                intent.putExtra("icon", removeLists.get(position).getPic_url());
                intent.putExtra("title", removeLists.get(position).getName());
                intent.putExtra("price", removeLists.get(position).getTprice());
                intent.putExtra("content", removeLists.get(position).getAttr());
                startActivity(intent);
            }
        });
    }
}
